package server.main.controller;


//import com.alibaba.fastjson.JSONObject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import server.main.service.AccountService;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/after")
public class AfterController {

    @Autowired
    AccountService accountService;


    @PostMapping("/savepersonality")
    public Map<String ,Object> savepersonality(@RequestBody String jsonString) {
        Map<String ,Object> map = new HashMap<>();
        JSONObject json = JSON.parseObject(jsonString);
        if(accountService.saveper(json)){
//            System.out.println(json.toJSONString());
            map.put("code",200);
            map.put("msg","更新成功！");
        }else {
            map.put("code",400);
            map.put("msg","更新失败，请稍后尝试！");

        }
        return map;
    }



    @GetMapping("/getmenu")
    public Map<String ,Object> getmenu(@RequestParam String name){

        Map<String ,Object> map = new HashMap<>();


        String menuJsonString = accountService.getMenuJsonString(name);
        map.put("menu",menuJsonString);


        return map;
    }





}
